<?php
require_once("xforms/Core.php");

class XForms_select extends XForms_Core {
  protected $tpl = 
  '<div class="xforms_select{renderClass}" >
	{renderHelp}{renderLabel}{required}
	<div{renderId}>
		{renderOptions}
	</div>
	
	<div class="xforms_validationmessage">
	</div>
	
	{renderHint}
    <br />
  </div>';
  protected $script = '.append(new XForms_select({renderJson}))';
  
   function renderClass(){
  $cssClass="";
  $binding = $this->getBinding();
  if($binding && $binding->getAttribute("relevant")) {

    $xBinding = $this->getXElement($binding);
    switch($xBinding->evalAttribute("relevant")){
      case true: break;
      case false: $cssClass= $cssClass . " xforms_nonvisible";break;
      default:
    }
  }
  return $cssClass;
}
  
  function renderOptions(){
    return parent::renderChildNodes(array('xforms:item','xforms:itemset'));
  }
 
  function renderHelp(){
    return $this->renderChildNodes(array("xforms:help"));
  }
  function renderHint(){
    return $this->renderChildNodes(array("xforms:hint"));
  }

   function renderLabel(){

    return $this->renderChildNodes(array("xforms:label"));
  }

  
  function required(){
  $required="";
  $binding = $this->getBinding();
  if($binding && $binding->getAttribute("required")) {
   $xBinding = $this->getXElement($binding);
    switch($xBinding->evalAttribute("required")) {
      case true: $required='<b style="color:red"> *</b>'; break;
      case false: break;
      default:
    }
  }
  return $required;
}
}
